<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
use Myredis\Myredis;

class House extends Controller
{

    public function house(Request $request)
    {
        if(empty($request->session('uid'))){
            $data['status']=true;
            $data['info']='您还未登入,请先登入哦';
            return json($data);
        }

        $uid=$request->session('uid');
        $gid=$request->post('gid');
        $info['uid']=$uid;
        $info['gid']=$gid;

        $result=Db::table('xo_user_goods')->field('id')->where(['uid'=>$uid,'gid'=>$gid])->find();
        if($result>0){
            $data['status']=true;
            $data['info']='不能重复收藏';
            return json($data);
        }

        $res=Db::table('xo_user_goods')->insert($info);
        if($res>0){
            $house=Myredis::hincrby('house',$gid,'1');
            $list['house']=$house;
            Db::table('xo_goods_up')->where(['id'=>$gid])->update($list);
            $data['status']=true;
            $data['info']='收藏成功';
        }else{
            $data['status']=false;
            $data['info']='收藏失败';
        }
        return json($data);
    }


}
